﻿using System;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Commands
{
    public class CommandExecutionContext
    {
        private Action alternateAction;


        public bool IsCanceled { get; private set; }

        public string CanceledReason { get; private set; }


        public void Cancel(string reason)
        {
            Cancel(reason, null);
        }

        public void Cancel(string reason, Action alternateAction)
        {
            if (IsCanceled)
            {
                return;
            }

            IsCanceled = true;
            CanceledReason = reason;
            this.alternateAction = alternateAction;
        }

        public void ExecuteAlternateAction()
        {
            if (alternateAction != null)
            {
                alternateAction();
            }
        }
    }
}
